"""FastAPI主应用"""

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from config.settings import config
from api.routes import chat, health


def create_app() -> FastAPI:
    """创建FastAPI应用"""
    app = FastAPI(
        title=config.app_name,
        version=config.app_version,
        description=config.app_description,
        debug=config.api.debug
    )
    
    # CORS中间件
    app.add_middleware(
        CORSMiddleware,
        allow_origins=config.api.cors_origins,
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    
    # 注册路由
    app.include_router(health.router, prefix="/api", tags=["health"])
    app.include_router(chat.router, prefix="/api", tags=["chat"])
    
    return app


# 创建应用实例
app = create_app()
